

<template>
    <div class="storeInfo supplier">
        <div class="head">
            <el-form class="headForm">
                <el-button type="success"  @click="theClick">添加</el-button>               
            </el-form>
            
        </div> 
        <!-- <p style="line-height:30px;padding-left:20px;margin-top:8px;color:#333" v-if="form.order_id == ''">最近{{total}}笔人工退款订单记录</p> -->
        <!-- table -->
        <div class="tabContainer_SI tabContainer">
            <el-table :data="tableData" stripe style="width: 100%;text-align:center" >
                <!-- 序号	卡座名称	类型	最低消费	推荐套餐	当前状态	更新时间	操作				 -->
                <el-table-column prop="deck_id" label="序号" fixed ></el-table-column>
                <el-table-column prop="deck_name" label="卡座名称"> </el-table-column>
                <el-table-column prop="deck_type_cn" label="类型" ></el-table-column>
                <el-table-column prop="minimum_consumption" label="最低消费"></el-table-column>
                <el-table-column prop="give_num" label="推荐套餐">
                    <template slot-scope="scope">
                        <div v-if="scope.row.recommend_combos.length != 0">
                            <p v-for="rcitem in scope.row.recommend_combos" :key="rcitem.combo_id">{{rcitem.combo_name}}</p>
                        </div>
                    </template>
                </el-table-column>               
                <el-table-column prop="deck_status_cn" label="当前状态"></el-table-column>
                <el-table-column prop="create_time" l abel="更新时间" ></el-table-column>
                 <el-table-column prop="" label="操作" v-if="limitList.length != 0">
                    <template slot-scope="scope">
                        <span v-for="(item,indexLimit) in limitList" :key="indexLimit" class="lightFont" @click="theClick(item.url,scope.row)">
                            <i>{{item.name}}</i>
                            <i v-if="indexLimit != limitList.length-1">&nbsp;|&nbsp;</i>
                        </span>
                    </template>          
                </el-table-column>
                <el-table-column v-else label="操作">/</el-table-column>

            </el-table>                       
        </div>
        <!-- 分页部分 -->
        <el-pagination
            background
            layout="total, prev, pager, next, jumper"
            @current-change="changePage"
            :page-size="size"
            :current-page.sync="pageNum"
            :hide-on-single-page=true
            :total="total">{{total}}
        </el-pagination>
        <el-dialog :title="title" :visible.sync="addalertShow" class="business">
            <el-form ref="form" :model="editparams" label-width="120px">
                <el-form-item label="卡座名称">
                    <el-input v-model="editparams.deck_name" type="text"></el-input>
                </el-form-item>    
                <el-form-item label="类型">
                    <el-radio v-model="editparams.deck_type" label="1">卡座</el-radio>
                    <el-radio v-model="editparams.deck_type" label="2">小桌</el-radio>
                </el-form-item>

                <el-form-item label="最低消费">
                    <el-input v-model="editparams.price" type="text"></el-input>
                </el-form-item>  

                <el-form-item label="推荐套餐" resize="none" class="needPosition">
                    <el-input v-model="keyword"></el-input>
                    <ul class="searchResult" v-if="searchlist.length != 0">
                        <li v-for="sitem in searchlist" :key="sitem.store_id" @click="getItem(sitem)">{{sitem.combo_name}}</li>
                    </ul>
                    <div style="margin-top:10px" v-if="pshowList.length != 0">
                        <p class="storeListshow" v-for="(pitem,i) in pshowList" :key="i">
                           <span>{{pitem.combo_name}}</span> 
                           <span style="color:red" @click="delspan(i)">X</span>
                        </p>
                    </div>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="addalertShow = false">取 消</el-button>
                <el-button type="primary" @click="comfirm">确 定</el-button>
            </div>
        </el-dialog>

    </div>
</template>

<style lang="scss">
.supplier{
        .el-dialog{
            .el-dialog__body{
                min-height: 300px;

            }
        } 
    }
  .tabContainer_SI{
      .el-table{
          .cell{
              text-align: center;
          }
      }
  }
</style>
<style lang="less" scoped>
.info{
    margin-top: -20px;
    margin-bottom: 15px;
    margin-left: 120px;
    color: orange;
}
.needPosition{
    position: relative;
    .storeListshow{
        display: flex;
        border:1px solid #ccc;
        border-radius: 2px;
        padding:5px;
        line-height: 30px;
        margin-bottom: 15px;
        font-size:14px;
        justify-content:space-between;
    }  
    .searchResult{
        position: absolute;
        left: 0;
        top:40px;
        width:100%;
        background: #fff;
        box-shadow: 0 0 10px rgba(0,0,0,0.5);
        li{
            padding:5px;
            font-size: 14px;
        }
    }  
}

</style>
<script>
import Vue from 'vue';
import { abc } from "../../../../js/abc.js";
import {potUrl} from '../../../../js/config_url.js'; 

export default {
    data () {
    return {
        searchparams:'',
        tableData:[],
        total:50,
        size:20,
        form:{size:20,
            page:1
        },
        pageNum:1,
        catelist:[],
        limitList:[
            {name:"编辑",url:"edit"}
        ],
        addalertShow:false,
        title:"",
        keyword:"",
        searchlist:[],
        pshowList:[],
        editparams:{
            deck_name:'',
            deck_type:'1',
            price:'',
            combos:''
        }

    }
  }, 
  watch:{
      keyword(n){
          const that = this;
        if(that.keyword == ''){
            that.searchStorelist = []
            return
        }
        abc.get(that,potUrl.barcombo,{keywords:that.keyword},(res)=>{
          that.searchlist = res.data
        }) 
      },
      addalertShow(){
          const that = this;          
          that.pshowList = []
      }
  },
   mounted(){
      let that = this;
      that.getList();
      abc.get(that,potUrl.categoryList,{},(res)=>{
          that.catelist = res.data
      })
  },
  methods:{
    search(){
        let that = this;
        //搜索有问题，搜索2019-03数据和2019-04数据是一样的；-error
        that.getList()
    },
    changePage(val){
        var that = this;
        that.pageNum = val;
        that.form.page = val;
        that.getList()
    },
    getList(){
        let that = this;
        abc.get(that,potUrl.barindex,that.form,(res)=>{
            that.tableData=res.data.list;
            that.total = res.data.total;
        })//列表
    },
    getItem(item){
        const that = this;
        that.pshowList.push(item);
        that.searchlist = [];
        that.keyword = ''
    },
    delspan(i){
        const that = this;
        that.pshowList.splice(i,1)
    },
    comfirm(){
        const that = this;
        var arr = [];
        that.addalertShow = false;
        that.pshowList.map((item)=>{
            arr.push(item.combo_id)           
        })
        that.editparams.combos = arr.join(',')
        abc.post(that,potUrl.bardone,that.editparams,(res)=>{
            that.getList()
        })
    },
    theClick(a,b){
        const that = this;
        that.addalertShow = true;
        if(a == 'edit'){
            that.title = '编辑：'+b.deck_name
            abc.get(that,potUrl.bardetail,{deck_id:b.deck_id},(res)=>{
                that.editparams.deck_name = res.data.deck_name
                that.editparams.deck_type = res.data.deck_type
                that.editparams.price = res.data.minimum_consumption
                that.pshowList = res.data.recommend_combos;
                that.editparams.deck_id = res.data.deck_id;
            })
        }else{
            that.title = '添加'
           that.editparams.deck_id = '' 
        }
    }
  }
}
</script>
